﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Web.SessionState;

public class Handler : IHttpHandler,IRequiresSessionState {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "application/javascript";
        JavaScriptSerializer ser = new JavaScriptSerializer();
        if (context.Request["ID"] != null) {
            int MaDe = int.Parse(context.Request["ID"].ToString());
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            Random rnd = new Random();
            List<CauHoiINFO> ds = ChiTietDeThiDAL.listByCauHoiClient(MaDe);
            
            ser.RegisterConverters(new[] { new JSONConverter<CauHoiINFO>("SoLuaChon") });
            
            sb.Append("var dsCauHoi = ").Append(ser.Serialize(ds)).Append(";");
            string smacauhoi = "";
            for (int i = 0; i < ds.Count; i++)
            {
                smacauhoi += ds[i].MaCH;
                if (i < ds.Count - 1)
                    smacauhoi += ",";
            }

            List<DapAnINFO> dsDA = DapAnDAL.listByCauHoi(smacauhoi);
            ser.RegisterConverters(new[] { new JSONConverter<DapAnINFO>("GiaTri") });
            sb.Append("var dsDapAn = ").Append(ser.Serialize(dsDA)).Append(";");

            string dsBaiLam = ChiTietBaiThiDAL.dsChonClient(context.Session["BaiThi"].ToString());
            sb.Append("var dsChon = ").Append(dsBaiLam).Append(";");
            
            context.Response.Write(sb.ToString());
        }
        context.Response.End();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}